<?php

App::uses('AppController', 'Controller');

class SitemapController extends AppController {
	
	public $components = array( 'RequestHandler' );
	public $layout = 'xml/default';
	
	public $uses = array('Group', 'Page', 'Product');
	
	public function index() {
		$this->RequestHandler->respondAs('xml');
		
		$urls = array('/', '/kontakt');
		
		$pages = $this->Page->find('all', array('fields'=>array('Page.*'), 'recursive'=>0));
		foreach ($pages as $page) {
			$urls[] = '/page/' . sprintf("%03d", $page['Page']['id']) . '/' . strtolower(urlize($page['Page']['menu_label']));
		}
		
		$groups = $this->Group->find('all', array('fields'=>array('Group.*'), 'recursive'=>0));
		foreach ($groups as $group) {
			$urls[] = '/products/index/' . $group['Group']['key'];
		}
		
		$products = $this->Product->find('all', array('fields'=>array('Product.*', 'Group.*'), 'recursive'=>0));
		foreach ($products as $product) {
			$urls[] = '/products/view/' . $product['Group']['key'] . '/' .
										  $product['Product']['id'] . '/'.
										  strtolower(urlize($product['Product']['name']));
		}
		
		
		$this->set('urls', $urls);
	}
	
}
